import QtQuick 2.0
import Qt.labs.folderlistmodel 2.1

import '../../fileTypeGetter.js' as FileTypeGetter

AbstractList {
    id: list

    GridView {
        id: gridView

        delegate: panelSimpleDelegate
        anchors.fill: parent
        model: list.model
        clip: true
        focus: true
        width: 100
        height: 40
        highlight: Rectangle { color: "lightsteelblue"; radius: 5 }


        header: Rectangle {
            width: 25
            height: 25

            Image {
                anchors.fill: parent
                source: "up_icons.png"
            }

            //Text {
            //text: "Up"
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    view.model.folder = view.model.parentFolder
                }
            }
        }




        Component {
            id: panelSimpleDelegate
            Column {
                id: delegate
                spacing: 5

                property string fullName: gridView.model.folder + '/' + fileName

                onFullNameChanged: {
                    var fileType = FileTypeGetter.getFileType(fullName);
                    //console.log('fileName.....>>>', fullName, stringEndsWith2(fullName, imgExts))
                    if (fileType == 'image') {
                        imgIcon.source = fullName;
                        imgIcon.visible = true;
                    }
                }

                Rectangle {
                    id: recBorder
                    color: delegate.GridView.isCurrentComponent? 'blue' : 'grey'
                    border.color: "black"
                    width: 90
                    height:90

                    MouseArea {
                        anchors.fill: parent
                        hoverEnabled: true

                        onDoubleClicked: {
                            var f = view.model.folder.toString();

                            console.log(typeof(f));
                            console.log('fileIsDir' + '>>>' + fileIsDir);



                            if(f.substring(f.length-1) != "/")
                                //                    if(f.right(1) != "/")
                            {
                                f += "/";
                            }
                            f += fileName;
                            view.model.folder = f;
                        }

                         onClicked: list.preview(delegate.fullName)
                         //onExited: list.preview('')
                    }

                    Rectangle {
                        id: icon
                        color: "#e48585"
                        border.color: "black"
                        gradient: Gradient {
                            GradientStop {
                                position: 0.19;
                                color: "#a1f763";
                            }
                            GradientStop {
                                position: 1.00;
                                color: "#ffffff";
                            }
                        }


                        anchors.top: recBorder.top
                        anchors.topMargin: 10
                        anchors.left:recBorder.left
                        anchors.leftMargin: 20
                        anchors.right: recBorder.right
                        anchors.rightMargin: 20
                        anchors.bottom: recBorder.bottom
                        anchors.bottomMargin: 30

                        Image {
                            id: imgIcon
                            anchors.fill: parent
                            visible: false


                        }


                    }

                    Text {
                        id: fileNameText
                        clip: true
                        width: recBorder.width
                        //wrapMode: Text.WordWrap
                        elide: Text.ElideRight
                        color: "black"
                        text: fileIsDir ? '[' + fileName + ']' : fileName
                        font.family: "Plantagenet Cherokee"
                        font.bold: fileIsDir ? true : false
                        verticalAlignment: Text.AlignBottom
                        horizontalAlignment: Text.AlignHCenter

                        styleColor: "#751ed1"
                        font.pointSize: 12

                        anchors.bottom: recBorder.bottom
                        anchors.left: recBorder.left
                        anchors.right: recBorder.right
                        visible: true






                        }

                    }

                }


            }
        }
    }




